package cn.ld.module.system.dal.mapper.mail;

import cn.ld.framework.common.pojo.PageResult;
import cn.ld.framework.mybatis.core.mapper.BaseMapperX;
import cn.ld.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.ld.framework.mybatis.core.query.QueryWrapperX;
import cn.ld.module.system.controller.admin.mail.vo.template.MailTemplatePageInVO;
import cn.ld.module.system.dal.entity.mail.MailTemplateEntity;
import cn.ld.module.system.dal.entity.sms.SmsTemplateEntity;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.Date;

@Mapper
public interface MailTemplateMapper extends BaseMapperX<MailTemplateEntity> {

    default PageResult<MailTemplateEntity> selectPage(MailTemplatePageInVO pageInVO){
        return selectPage(pageInVO , new LambdaQueryWrapperX<MailTemplateEntity>()
                .eqIfPresent(MailTemplateEntity::getStatus, pageInVO.getStatus())
                .likeIfPresent(MailTemplateEntity::getCode, pageInVO.getCode())
                .likeIfPresent(MailTemplateEntity::getName, pageInVO.getName())
                .eqIfPresent(MailTemplateEntity::getAccountId, pageInVO.getAccountId())
                .betweenIfPresent(MailTemplateEntity::getCreateTime, pageInVO.getCreateTime()));
    }

    default Long selectCountByAccountId(Long accountId) {
        return selectCount(MailTemplateEntity::getAccountId, accountId);
    }

    default MailTemplateEntity selectByCode(String code) {
        return selectOne(MailTemplateEntity::getCode, code);
    }

}
